/**
 * @(#)ItemAjaxController.java, 2018/2/8.
 * <p/>
 * Copyright 2018 Kerr Wang, Inc. All rights reserved.
 * KERRWANG PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package org.wangzx.exercise.controller.xhr;

import com.alibaba.fastjson.JSON;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.wangzx.exercise.meta.vo.ItemVO;
import org.wangzx.exercise.meta.vo.common.AjaxResult;
import org.wangzx.exercise.service.basic.ItemService;

import javax.servlet.http.HttpServletRequest;

/**
 * @author hzwangzuxiang(ahscwzx@163.com)
 */
@Controller
@RequestMapping("/")
public class ItemAjaxController extends BaseAjaxController {
    static private final Logger logger = LoggerFactory.getLogger(ItemAjaxController.class);

    @Autowired
    private ItemService itemService;

    @RequestMapping(value = "/edit.json", method = RequestMethod.POST)
    @ResponseBody
    public AjaxResult editItem(@RequestBody ItemVO itemVO, HttpServletRequest request) {
        logger.info("[op:editItem] edit item, itemVO={}", JSON.toJSONString(itemVO));

        boolean result = itemService.updateItem(itemVO);
        if(!result) {
            logger.error("[op:editItem] edit itemVO failed, itemVO={}", JSON.toJSONString(itemVO));
        }
        return initSuccessResult(result);
    }
}
